﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<CRM.Database.Model.TrainingsSchedules>>" %>
<%@ Import Namespace="CRM.Resourses" %>

<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdTrainingsSchedule";
                                        settings.KeyFieldName = "IdTrainingsSchedule";
                                        settings.CallbackRouteValues = new { Controller = "TC", Action = "TrainingsSchedulesPartial" };
                                        settings.SettingsPager.PageSize = 20;
                                        settings.Settings.ShowFilterRow = true;
                                        settings.Height = 100;

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsCourseName;
                                            column.FieldName = "IdTrainingsSchedule";
                                            column.ColumnType = MVCxGridViewColumnType.HyperLink;
                                            column.Settings.FilterMode = ColumnFilterMode.DisplayText;
                                            column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
                                            var properties = column.PropertiesEdit as HyperLinkProperties;
                                            var urlFormatString = Url.Action("TrainingsSchedulesEdit", "TC", new RouteValueDictionary(new { idTrainingsSchedule = "{0}" }));
                                            if (properties != null)
                                            {
                                                properties.NavigateUrlFormatString = HttpUtility.UrlDecode(urlFormatString);
                                                properties.TextField = "CourseName";
                                            }
                                        });

                                        ////Добавление комбобоксов
                                        //settings.Columns.Add(column =>
                                        //{
                                        //    column.FieldName = "IdTrainingsCource";

                                        //    column.Caption = Resourses.TrainingsCourseName;
                                        //    column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                        //    var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                        //    if (comboBoxProperties != null)
                                        //    {
                                        //        comboBoxProperties.DataSource = DB.TrainingsCoursesActive;
                                        //        comboBoxProperties.TextField = "Name";
                                        //        comboBoxProperties.ValueField = "IdTrainingsCourse";
                                        //        comboBoxProperties.ValueType = typeof(int);
                                        //    }
                                        //});
                                        ////конец комбобокса

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsDate;
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                            column.FieldName = "PlannedDate";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsCustomerName;
                                            column.FieldName = "CustomerName";
                                        });

                                        //Добавление локализованного комбобокса
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTrainingsPlace";
                                            column.Caption = Resourses.TrainingsPlace;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var placesCol = new CRM.Database.Model.TrainingsPlacesCollection();
                                                comboBoxProperties.DataSource = placesCol.TrainingsPlacesList;
                                                //comboBoxProperties.DataSource = DB.GetLocalizedTrainingsPlacesNames(Thread.CurrentThread.CurrentCulture.ToString());
                                                //comboBoxProperties.DataSource = DB.GetTrainingsPlacesListByCourse(DB.GetTrainingsPlacebyId())
                                                comboBoxProperties.TextField = "LocalizedName";
                                                comboBoxProperties.ValueField = "IdTrainingsPlace";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса

                                        //Добавление комбобоксов
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTrainingsTrainer";
                                           
                                            column.Caption = Resourses.TrainingsTrainer;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var trainersCol = new CRM.Database.Model.TrainingsTrainersCollection();
                                                comboBoxProperties.DataSource = trainersCol.TrainingsTrainersList;
                                                //comboBoxProperties.DataSource = DB.TrainingsTrainers.ToList();
                                                comboBoxProperties.TextField = "Name";
                                                comboBoxProperties.ValueField = "IdTrainingsTrainer";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса

                                        ////стоимость курса
                                        //settings.Columns.Add(column =>
                                        //{
                                        //    column.Caption = Resourses.TrainingsCourseCost;
                                        //    column.FieldName = "CourseCost";
                                        //    column.Width = 40;
                                        //});

                                        ////стоимость участника
                                        //settings.Columns.Add(column =>
                                        //{
                                        //    column.Caption = Resourses.TrainingsParticipantCost;
                                        //    column.FieldName = "ParticipantCoctExt";
                                        //});

                                        ////допустимое кол-во участников
                                        //settings.Columns.Add(column =>
                                        //{
                                        //    column.Caption = Resourses.TrainingsCountAvailable;
                                        //    column.FieldName = "ParticipantsCountAvailable";
                                        //});

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsCountRequested;
                                            column.FieldName = "ParticipantsCountRequested";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsCountApproved;
                                            column.FieldName = "ParticipantsCountApproved";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsCountActual;
                                            column.FieldName = "ParticipantsCountActual";
                                        });

                                        //Добавление локализованного комбобокса
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTrainingCoursesStatus";
                                            column.Caption = Resourses.TrainingCoursesStatus;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var statusesCol = new CRM.Database.Model.TrainingCoursesStatusesCollection();
                                                comboBoxProperties.DataSource = statusesCol.TrainingCoursesStatusesList;
                                                //comboBoxProperties.DataSource = DB.GetLocalizedTrainingCoursesStatusesNames(Thread.CurrentThread.CurrentCulture.ToString());
                                                comboBoxProperties.TextField = "LocalizedName";
                                                comboBoxProperties.ValueField = "IdTrainingCoursesStatus";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingCoursesType;
                                            column.FieldName = "CourseTypeLocalazed";
                                            //column.FieldName = "CourseTypeLocalazed";
                                        });

                                        //settings.Columns.Add(column =>
                                        //{
                                        //    column.Caption = "#";
                                        //    column.SetDataItemTemplateContent(c =>
                                        //    {
                                        //        ViewContext.Writer.Write(
                                        //            //Html.ActionLink("Изменить", "TrainingsSchedulesEdit", new { idTrainingsSchedule = DataBinder.Eval(c.DataItem, "IdTrainingsSchedule") }) + 
                                        //            //"&nbsp;" +
                                        //            //Html.ActionLink("Отменить", "TrainingsSchedulesCancel", new { idTrainingsSchedule = DataBinder.Eval(c.DataItem, "IdTrainingsSchedule") }) +
                                        //            //"&nbsp;" +
                                        //            Html.ActionLink("Удалить", "TrainingsSchedulesDelete", new { idTrainingsSchedule = DataBinder.Eval(c.DataItem, "IdTrainingsSchedule") },
                                        //                new { onclick = "return confirm('Удалить учебный курс?')" })
                                        //        );
                                        //    });
                                        //    //column.SetHeaderTemplateContent(c =>
                                        //    //{
                                        //    //    ViewContext.Writer.Write(
                                        //    //        Html.ActionLink("Добавить", "TrainingsSchedulesEdit", new { idTrainingsSchedule = -1 }).ToHtmlString()
                                        //    //    );
                                        //    //});
                                        //    column.Settings.AllowDragDrop = DefaultBoolean.False;
                                        //    column.Settings.AllowSort = DefaultBoolean.False;
                                        //    column.Width = 50;
                                        //});
                                        
                                        //Добавление редактирования
                                        //settings.CommandColumn.Visible = true;
                                        //settings.CommandColumn.NewButton.Visible = true;
                                        //settings.CommandColumn.DeleteButton.Visible = true;
                                        //settings.CommandColumn.EditButton.Visible = true;
                                        //settings.SettingsBehavior.ConfirmDelete = true;
                                        //settings.Settings.ShowFilterRow = true;
                                        //settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "TC", Action = "TrainingsSchedulesPartialUpdate" };
                                        //settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "TC", Action = "TrainingsSchedulesPartialAdd" };
                                        //settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "TC", Action = "TrainingsSchedulesPartialDelete" };
                                        //settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                        //settings.Width = Unit.Percentage(100);
                                        
                                     }).Bind(Model.ToList()).GetHtml();%>
